#include "base/log.h"
#include <unistd.h>
#include "net/tcpclient.h"
#include "net/connect.h"
#include "base/config.h"
#include "base/logthread.h"
#include "MyRpc/message.h"
#include "MyRpc/rpc.h"
#include "base/function.h"

#include <sys/time.h>

myrpc::Message *message = nullptr;
myrpc::base::Rpc *rpc = nullptr;

void close_func(net_tools::net::Connect *connect)
{
  connect->Print_ip_port("close");
};
char buf[1500] = {};
void read_func(net_tools::net::Connect *connect)
{
  connect->Write(buf, connect->Read(buf, 1500));
};
void conn_func(net_tools::net::Connect *connect)
{
  connect->Print_ip_port("connect");
  connect->Set_read_callback(read_func);
  connect->Set_close_callback(close_func);
  NT_LOG_INFO << "connect ready" << NT_LOG_ENDL;
  connect->Write(buf, 1500);
};

int main(int argc, char *argv[])
{
  net_tools::Config config("Client");
  net_tools::Log log_;
  message = myrpc::Message::Get_singleton();
  rpc = message->Get_rpc();
  net_tools::Tcpclient tcp;
  tcp.Set_connect_over_callback(conn_func);
  tcp.Startclient(true);
  NT_LOG_INFO << "pause" << NT_LOG_ENDL;
  pause();
};